<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" inline label-width="100px">
            <span class="seachTiele">{{ $t('shiJianXuanZe') }}：</span>
            <el-radio-group
              v-model="tableFrom.dateLimit"
              type="button"
              class="mr20"
              size="small"
              @change="selectChange(tableFrom.dateLimit)"
            >
              <el-radio-button v-for="(item, i) in fromList.fromTxt" :key="i" :label="item.val">{{
                $t(item.text)
              }}</el-radio-button>
            </el-radio-group>
            <el-date-picker
              v-model="timeVal"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              size="small"
              type="daterange"
              placement="bottom-end"
              :placeholder="$t('ziDingYiShiJian')"
              style="width: 250px"
              @change="onchangeTime"
            />
            <div class="mt20">
              <span class="seachTiele">{{ $t('guanJianZi') }}：</span>
              <el-input v-model="tableFrom.orderNo" :placeholder="$t('tishi14')" class="selWidth mr20" />
              <el-button size="small" type="primary" icon="el-icon-search" @click="getList">{{ $t('chaXun') }}</el-button>
              <!--<el-button size="small" type="primary" icon="el-icon-top" @click="exportRecord">列表导出</el-button>-->
              <!--<el-button size="small" type="primary" @click="getExportFileList">导出记录</el-button>-->
            </div>
          </el-form>
        </div>
      </div>
      <!--<cards-data :card-lists="cardLists" />-->
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        :span-method="objectSpanMethod"
        border
      >
        <el-table-column prop="merOrderCode" label="商户订单号" min-width="160" />
        <el-table-column prop="haOrderCode" :label="$t('halykDingDanBianMa')" min-width="100" />
        <el-table-column prop="mainOrderCode" :label="$t('pingTaiDingDanBianMa')" min-width="180" />
        <el-table-column prop="haUserName" :label="$t('shouHuoRenXingMing')" min-width="100" />
        <el-table-column prop="skuName" label="SKU" min-width="280" />
        <el-table-column prop="payNum" :label="$t('shuLiang')" min-width="60" />
        <el-table-column prop="merTotalPrice" :label="$t('skuJinE')" min-width="100" />
        <el-table-column prop="allMerTotalPrice" :label="$t('dingDanZongJinE')" min-width="100" />
        <el-table-column prop="creationDate" :label="$t('dingDanShiJian')" min-width="140" />
        <el-table-column prop="statusName" :label="$t('dingDanZhuangTai')" min-width="100" />
        <el-table-column prop="currency" label="币种" min-width="100">
          <template slot-scope="scope">坚戈</template>
        </el-table-column>
        <!-- <el-table-column prop="operate" :label="$t('caoZuo')" min-width="70" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              class="mr10"
              @click.native="onOrderDetails(scope.row.id)"
              v-hasPermi="['platform:finance:monitor:info']"
              >{{ $t('xiangQing') }}
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <!--导出订单列表-->
    <!--<file-list ref="exportList" />-->
  </div>
</template>

<script>
import Cookies from 'js-cookie'
import { capitalFlowLstApi, capitalFlowExportApi, getStatisticsApi } from '@/api/accounts'
// import detailsFrom from '@/views/order/orderDetail'
import { checkPermi } from '@/utils/permission' // 权限判断函数
export default {
  data() {
    return {
      orderId: '',
      tableData: {
        data: [],
        total: 0
      },
      listLoading: true,
      tableFrom: {
        orderNo: '',
        dateLimit: '',
        page: 1,
        limit: 20
      },
      timeVal: [],
      fromList: this.$constants.fromList,
      selectionList: [],
      ids: '',
      tableFromLog: {
        page: 1,
        limit: 10
      },
      tableDataLog: {
        data: [],
        total: 0
      },
      LogLoading: false,
      dialogVisible: false,
      cardLists: [],
      orderDatalist: null
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    checkPermi,
    // 选择时间
    selectChange(tab) {
      this.tableFrom.dateLimit = tab
      this.timeVal = []
      this.getList()
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e
      this.tableFrom.dateLimit = e ? this.timeVal.join(',') : ''
      this.getList()
    },
    // 导出
    exportRecord() {
      capitalFlowExportApi(this.tableFrom)
        .then((res) => {
          const h = this.$createElement
          this.$msgbox({
            title: this.$t('tiShi'),
            message: h('p', null, [
              h('span', null, this.$t('tishi4')),
              h('span', { style: 'color: teal' }, this.$t('daoChuJiLu')),
              h('span', null, this.$t('chaKan'))
            ])
          }).then((action) => {})
        })
        .catch((res) => {
          this.$message.error(res.message)
        })
    },
    // 导出列表
    getExportFileList() {
      this.$refs.exportList.exportFileList()
    },
    // 列表
    getList() {
      this.listLoading = true
      const merId = JSON.parse(Cookies.get('JavaMerInfo')).id
      capitalFlowLstApi({ merId, ...this.tableFrom })
        .then((res) => {
          const list = []
          res.list.forEach((item) => {
            if (item.detailList) {
              // let allTotalPrice = 0
              // item.detailList.forEach((item2) => {
              //   allTotalPrice += Number(item2.totalPrice)
              // })
              item.detailList.forEach((item2) => {
                list.push({ ...item, ...item2, allMerTotalPrice: item.merTotalPrice, id: item.id })
              })
            } else {
              list.push(item)
            }
          })

          this.tableData.data = list
          this.tableData.total = res.total
          this.listLoading = false
        })
        .catch((res) => {
          this.listLoading = false
        })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList()
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (
        ['merOrderCode', 'merId', 'merName', 'mainOrderCode', 'haOrderCode', 'haUserName', 'allTotalPrice', 'creationDate', 'statusName', 'currency'].includes(column.property)
      ) {
        if (rowIndex === 0 || row.id != this.tableData.data[rowIndex - 1].id) {
          let rowspan = 0
          this.tableData.data.forEach((element) => {
            if (element.id === row.id) {
              rowspan++
            }
          })
          return [rowspan, 1]
        } else {
          return [0, 0]
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.selWidth {
  width: 300px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}
.mt20 {
  margin-top: 20px;
}
.demo-image__preview {
  position: relative;
  padding-left: 40px;
}
.demo-image__preview .el-image,
.el-image__error {
  position: absolute;
  left: 0;
}
.maxw180 {
  display: inline-block;
  max-width: 180px;
}
</style>
